파일카피 메소드 :: 자주 쓰이는 메소드및 API 를 정리합니다.[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

자주 쓰이는 메소드및 API 를 정리합니다.
[1]
등록일:2008-03-10 16:45:08 (0%)
작성자:
제목:파일카피 메소드
        /*
          *  
          *  File를  copy하자...
          */
public  static  void  copyFile(String  source,  String  dest,  boolean  bRemoveSource)  throws  IOException      
{            
FileInputStream   fileInput           =  null;            
FileOutputStream   fileOutput       =  null;            
boolean   bCanWrite              =  false;            
boolean   bDeleted                =  false;    

File  fileSource  =  new  File(source);            
File  fileDest  =  new  File(dest);            
long  time  =  fileSource.lastModified();            

try            
{                
fileInput    =  new  FileInputStream(source);                
fileOutput  =  new  FileOutputStream(dest);                
copyStream(fileInput,  fileOutput);            
}            
finally            
{                
try                
{                    
if  (fileInput  !=  null)  fileInput.close();                
}              
catch  (IOException  e)  {}                
try                
{                    
if  (fileOutput  !=  null)  
fileOutput.close();                
}                
catch  (IOException  e)  {}            
}            
fileInput.close();            
fileOutput.close();          

fileDest.setLastModified(time);            
if  (bRemoveSource  ==  true)            
{                  
bCanWrite  =  fileSource.canWrite();                  
if  (bCanWrite)    
{                        
bDeleted  =  fileSource.delete();                  
}          
}      
}      

public  static  void  copyStream(InputStream  in,  OutputStream  out)    throws  IOException      
{                  
synchronized  (in)    
{                  
synchronized  (out)    
{                        
byte[]  buffer  =  new  byte[1024];                    
while  (true)    
{                              
int  bytesRead  =  in.read(buffer);                              
if  (bytesRead  ==  -1)                                    
break;                              
out.write(buffer,  0,  bytesRead);                        
}                  
}            
}      
}
[본문링크] 파일카피 메소드
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=2477
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.